package cn.yunhe.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.yunhe.entity.Instrument;
import cn.yunhe.service.InstrumentService;

@Controller
public class InstrumentController {
	@Autowired
	private InstrumentService instrumentService;
	@RequestMapping("/getInstrumentInfo")
	public ModelAndView findAllInstru(){
		System.out.println("==============详情 页面!!!=============");
		ModelAndView mav = new ModelAndView("instrumentInfo");
		List<Instrument> list = instrumentService.findInstrumentAllByLikeName("%"+""+"%");
		mav.addObject("inlist",list);
		
		return mav;
	}
	// 搜索 页面 模糊查询
	@RequestMapping("/searchInstrument")
	public ModelAndView searchInstrutment(String iname){
		System.out.println("==============详情 页面!!!=============");
		ModelAndView mav = new ModelAndView("instrumentInfo");
		List<Instrument> list = instrumentService.findInstrumentAllByLikeName("%"+iname+"%");
		mav.addObject("inlist",list);
		return mav;
	}
	@RequestMapping("/deletInstrumentByState")
	public ModelAndView deletInstrumentByState(int iid){
		System.out.println("==============删除  !!!=============");
		ModelAndView mav = new ModelAndView("instrumentInfo");
		int num = instrumentService.deleteInstrumentByIstate(iid);
		System.out.println(num+",,");
		List<Instrument> list = instrumentService.findInstrumentAllByLikeName("%"+""+"%");
		mav.addObject("inlist",list);
		
		return mav;
	}
	// 更新 页面   updateInstrumentByIid
	@RequestMapping("/updateInstrumentByIid")
	public ModelAndView updateInstrumentByIid(int iid,HttpServletRequest request){
		System.out.println("==============更新 医疗 器材 111111111  !!!=============");
		ModelAndView mav = new ModelAndView("instrumentAlter");
		Instrument instrument = instrumentService.findInstrumentByIid(iid);
		
		request.setAttribute("instrument", instrument);
		return mav;
	}
	@RequestMapping("/updateInstrumentByIid2")
	public ModelAndView updateInstrumentByIid2(Instrument instrument, HttpServletRequest request){
		System.out.println("==============更新 医疗 器材 22222222 !!!=============");
		ModelAndView mav = new ModelAndView("instrumentInfo");
		System.out.println(instrument.getIid()+","+instrument.getIname()+","+instrument.getInum()+","+instrument.getIprice()+",,"+instrument.getSupp().getPid());
		int num = instrumentService.updateInstrument(instrument);
		System.out.println(num+",,");
		// 跳转 主信息页面
		List<Instrument> list = instrumentService.findInstrumentAllByLikeName("%"+""+"%");
		mav.addObject("inlist",list);
		request.setAttribute("instrument", instrument);
		return mav;
	}
	// 增加 器械   状态值 记得 加
	@RequestMapping("/addInstrument")
	public ModelAndView addInstrument(Instrument instrument){
		System.out.println("=====================增加 医疗器械 !!!!================");
		ModelAndView mav = new ModelAndView("instrumentInfo"); 
//		instrument.setIstate(1);
//		int num = instrumentService.addInstrument(instrument);
//		System.out.println(num+",,");
		// 跳转 主信息页面
		List<Instrument> list = instrumentService.findInstrumentAllByLikeName("%"+""+"%");
		mav.addObject("inlist",list);
		return mav;
	}
	public InstrumentService getInstrumentService() {
		return instrumentService;
	}

	public void setInstrumentService(InstrumentService instrumentService) {
		this.instrumentService = instrumentService;
	}
	
	
}
